package com.zqq.myrxhttp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.zqq.myrxhttp.widgets.AnimatorListener;
import com.zqq.myrxhttp.widgets.BottomPopupWindowView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private BottomPopupWindowView bottomPopupWindowView;
    private View contentView;
    private RecyclerView recyclerView;
    private ItemAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        (findViewById(R.id.pay_quanRL)).setOnClickListener(this);//点击弹出pop

        bottomPopupWindowView = (BottomPopupWindowView) findViewById(R.id.bottom_popup);
//        bottomPopupWindowView.setOnClickListener(this);

        contentView = LayoutInflater.from(this).inflate(R.layout.layout_content_view, null);
        bottomPopupWindowView.setContextView(contentView);
        recyclerView = contentView.findViewById(R.id.recycler);
        (contentView.findViewById(R.id.ic_cancel)).setOnClickListener(this);
//        bottomPopupWindowView.setAnimatorListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ic_cancel:
                bottomPopupWindowView.disMissPopupView();
                break;
            case R.id.pay_quanRL:
                bottomPopupWindowView.setVisibility(View.VISIBLE);
                bottomPopupWindowView.showPopouView();
                initView();
                break;
            default:
                break;
        }
    }

    private void initView() {
        adapter = new ItemAdapter(this);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);

        recyclerView.setAdapter(adapter);
    }


//    @Override
//    public void startValue(int value) {
////        setMargins(mainView, value - 10, value, value - 10, value);
//    }
//
//    @Override
//    public void endValue(int value) {
////        setMargins(mainView, value, value, value, value);
//    }

    public static void setMargins(View v, int l, int t, int r, int b) {
        if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
            p.setMargins(l, t, r, b);
            v.requestLayout();
        }
    }


}
